package 集合到文件改进;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

public class ArrayListToTxtDemo {
    public static void main(String[] args) throws IOException {
        ArrayList<Student> array=new ArrayList<>();
        BufferedReader br=new BufferedReader(new FileReader("111.txt"));
        String line;
        while((line= br.readLine())!=null){
            //把读取到的字符串数据用split()进行分割，得到一个字符串数组
            String[] strArray = line.split(",");
            Student s=new Student();
            s.setSid(strArray[0]);
            s.setName(strArray[1]);
            s.setAge(Integer.parseInt(strArray[2]));//int类型，调用Interger.parseInt()将字符串转化为Interger类型的数据
            s.setAddress(strArray[3]);

            array.add(s);
        }
        br.close();

        for (Student s:array){
            System.out.println(s.getSid()+","+s.getName()+","+s.getAge()+","+s.getAddress());
        }
    }
}
